package com.data.modules.gd.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.data.common.api.vo.Result;
import com.data.common.aspect.annotation.AutoLog;
import com.data.common.constant.WebsocketConst;
import com.data.common.constant.enums.DySmsEnum;
import com.data.common.constant.enums.EventEnum;
import com.data.common.constant.enums.ProductEnum;
import com.data.common.system.query.QueryGenerator;
import com.data.common.system.vo.DictModel;
import com.data.common.util.*;
import com.data.modules.base.service.BaseCommonService;
import com.data.modules.gd.service.IGdEventLogService;
import com.data.modules.gd.vo.CityRankVo;
import com.data.modules.gd.vo.EventLogVo;
import com.data.modules.gd.vo.TvRankVo;
import com.data.modules.hotel.entity.SmzhHotelPhoto;
import com.data.modules.hotel.service.ISmzhHotelPhotoService;
import com.data.modules.jd.entity.JdOutCard;
import com.data.modules.jd.service.IJdOutCardService;
import com.data.modules.jd.vo.OutCarReqVo;
import com.data.modules.jhl.entity.SmJhlFall;
import com.data.modules.jhl.service.ISmJhlFallService;
import com.data.modules.message.websocket.WebSocket;
import com.data.modules.sm.entity.SmBuilding;
import com.data.modules.sm.entity.SmProject;
import com.data.modules.sm.entity.SysConfig;
import com.data.modules.sm.service.ISmProjectService;
import com.data.modules.sm.service.ISysConfigService;
import com.data.modules.smapp.entity.SmAppAd;
import com.data.modules.smapp.entity.SmAppNews;
import com.data.modules.smapp.service.ISmAppAdService;
import com.data.modules.smapp.service.ISmAppNewsService;
import com.data.modules.smapp.vo.AdReqVo;
import com.data.modules.smzh.entity.*;
import com.data.modules.smzh.service.*;
import com.data.modules.smzh.vo.*;
import com.data.modules.system.entity.User;
import com.data.modules.system.service.ISysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @Author boot
 */

@RestController
@RequestMapping("/gdxw/api")
@Api(tags="gdxw")
@Slf4j
@SuppressWarnings("ALL")
public class GdController<stringWarnType> {
	@Autowired
	private ISmDeviceVersionService smDeviceVersionService;

	@Autowired
	private IGdEventLogService gdEventLogService;

	@ApiOperation(value="获取新闻屏设备统计", notes="获取新闻屏设备统计")
	@GetMapping(value = "/v1/getDeviceTotal")
	public Result<?> getDeviceTotal() {

		Map<String,Object> map = new HashMap<>();
		int total = smDeviceVersionService.lambdaQuery().eq(SmDeviceVersion::getModel,ProductEnum.SMW_GDXW.getCode()).count();
		int stopNum = smDeviceVersionService.lambdaQuery().eq(SmDeviceVersion::getModel,ProductEnum.SMW_GDXW.getCode())
				.eq(SmDeviceVersion::getStatus,1).count();

		map.put("total",total);
		map.put("stopNum",stopNum);
		return Result.ok(map);
	}

	@ApiOperation(value="获取当天5G云电视数据分析", notes="获取当天5G云电视数据分析")
	@GetMapping(value = "/v1/getTvData")
	public Result<?> getTvData() {

		Map map = smDeviceVersionService.queryTodayTvInfo();
		return Result.ok(map);
	}

	@ApiOperation(value="获取5G云电视近7天数据", notes="获取5G云电视近7天数据")
	@GetMapping(value = "/v1/getNearSevenTvData")
	public Result<?> getNearSevenTvData() {

		List<Map> list = smDeviceVersionService.querySevenDayTvInfo();
		return Result.ok(list);
	}


	@ApiOperation(value="获取近7天节目单排名数据", notes="获取近7天节目单排名数据")
	@GetMapping(value = "/v1/getNearSevenChannelData")
	public Result<?> getNearSevenChannelData() {

		List<Map> list = smDeviceVersionService.querySevenDayChannelData();
		return Result.ok(list.stream().filter(x->ObjectUtil.isNotEmpty(x.get("name"))).collect(Collectors.toList()));
	}

	@ApiOperation(value="获取近7天点击量城市排名", notes="获取近7天点击量城市排名")
	@GetMapping(value = "/v1/getNearSevenAllData")
	public Result<?> getNearSevenAllData() {

		List<CityRankVo> list = smDeviceVersionService.getNearSevenAllData();
		return Result.ok(list);
	}

	@ApiOperation(value="获取近7天点击量按照类型", notes="获取近7天点击量按照类型")
	@GetMapping(value = "/v1/getNearSevenAllDataByType")
	public Result<?> getNearSevenAllDataByType() {

		List<Map> list = smDeviceVersionService.getNearSevenClickData();
		return Result.ok(list);
	}

	@ApiOperation(value="获取近7天点击量按照时间和类型", notes="获取近7天点击量按照时间和类型")
	@GetMapping(value = "/v1/getNearSevenAllDataByTimeAndType")
	public Result<?> getNearSevenAllDataByTimeAndType() {

		List<Map> list = smDeviceVersionService.getSdTimeAndType();
		return Result.ok(list);
	}


	@ApiOperation(value="获取近7天平均浏览时长", notes="获取近7天平均浏览时长")
	@GetMapping(value = "/v1/getSevenAvgTime")
	public Result<?> getSevenAvgTime() {

		List<TvRankVo> list = gdEventLogService.getSevenAvgTime();
		return Result.ok(list);
	}

	@ApiOperation(value="获取各地区使用情况分析", notes="获取各地区使用情况分析")
	@GetMapping(value = "/v1/getAreaData")
	public Result<?> getAreaData() {

		List<CityRankVo> map = smDeviceVersionService.queryAreaData();
		return Result.ok(map);
	}


}
